#include "oBorder.h"

//#inculde "keyboard_adaptor.h"
//#include "keyboard_interface.h"


oBorder::oBorder(QWidget * parent) : QWidget(parent) {
    setGeometry(0,35,480,640-35);
    this->setWindowTitle("oBorder");
    this->setWindowFlags( Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    keyboard=false;

  /*  new KeyboardAdaptor(this);
    QDBusConnection::sessionBus().registerObject("/", this);
    com::opendesk::keyboard *iface;
    iface = new com::opendesk::keyboard(QString(), QString(),QDBusConnection::sessionBus(),this);*/

}

oBorder::~oBorder(){
}



void oBorder::paintEvent(QPaintEvent * event){
    QPainter p(this);

    p.setRenderHint(QPainter::TextAntialiasing);
    p.setRenderHint(QPainter::Antialiasing);

    p.save();
    p.setCompositionMode(QPainter::CompositionMode_Source);
    p.fillRect(rect(), Qt::transparent);
    p.restore();


//    p.drawRect(0,0, width(), height());

    QColor darkBlack(16,16,16,255);

    p.setPen(darkBlack);
    p.setBrush(darkBlack);

    p.save();
    p.drawRect(0,0,width(),height());
    p.restore();

    p.end();
}


void oBorder::resizeEvent(QResizeEvent * event) {
    int h;

    QList <point> list;
    point a;
    a.x=0;
    a.y=9;
    list.push_back(a);
    a.x=1;
    a.y=7;
    list.push_back(a);
    a.x=2;
    a.y=5;
    list.push_back(a);
    a.x=5;
    a.y=2;
    list.push_back(a);
    a.x=7;
    a.y=1;
    list.push_back(a);
    a.x=9;
    a.y=0;
    list.push_back(a);
    a.x=9;
    a.y=0;
    list.push_back(a);

    if (keyboard) {
        h = 210;
    }
    else h = 3;
    QPolygon maskPolygon(10+list.size()*2);
    maskPolygon.setPoint(0,0,0);
    maskPolygon.setPoint(1,3,0);
    maskPolygon.setPoint(2,3,height()-(13+h));
    for (int i=0; i< list.size(); i++) {
        maskPolygon.setPoint(3+i,3+list.at(i).x,height()-(h+list.at(i).y));
    }
    maskPolygon.setPoint(3+list.size(),16,height()-(h));
    maskPolygon.setPoint(4+list.size(),464,height()-(h));
    for (int i=0; i< list.size(); i++) {
        maskPolygon.setPoint(5+list.size()+i,width()-(12-list.at(i).x),height()-(h+list.at(list.size()-(1+i)).y));
    }
    maskPolygon.setPoint(5+list.size()*2,477,height()-(13+h));
    maskPolygon.setPoint(6+list.size()*2,477,0);
    maskPolygon.setPoint(7+list.size()*2,480,0);
    maskPolygon.setPoint(8+list.size()*2,480,height());
    maskPolygon.setPoint(9+list.size()*2,0,height());
    maskPolygon.end();
    QRegion maskRegion(maskPolygon);

    this->setMask(maskRegion);
}



